﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.actions {
    import Engine.Helpers.*;
    import Classes.*;

    public class ActionElevate extends NPCAction {

        protected var m_sourceElevation:Number;
        protected var m_targetElevation:Number;
        protected var m_velocityScale:Number = 1;
        protected var m_direction:int = -1;
        protected var m_ease:String = "none";
        private var m_duration:Number = 0;
        private var m_elapsed:Number = 0;
        private var m_progress:Number = 0;

        public function ActionElevate(_arg1:NPC, _arg2:Number, _arg3:Number=-1){
            super(_arg1);
            this.m_sourceElevation = _arg3;
            this.m_targetElevation = _arg2;
        }
        public function setVelocityScale(_arg1:Number):ActionElevate{
            this.m_velocityScale = _arg1;
            return (this);
        }
        public function setEase(_arg1:String):ActionElevate{
            this.m_ease = _arg1;
            return (this);
        }
        public function duration():Number{
            return (this.m_duration);
        }
        public function elapsed():Number{
            return (this.m_elapsed);
        }
        public function setDirection(_arg1:int):ActionElevate{
            this.m_direction = _arg1;
            return (this);
        }
        protected function get navigationVelocity():Number{
            return ((m_npc.velocityWalk * this.m_velocityScale));
        }
        override public function update(_arg1:Number):void{
            this.m_elapsed = (this.m_elapsed + _arg1);
            var _local2:Number = this.m_progress;
            var _local3:Number = Math.abs((this.m_sourceElevation - this.m_targetElevation));
            switch (this.m_ease){
                case ActionNavigateBeeline.EASE_NONE:
                    this.m_progress = (this.m_progress + (_arg1 * this.navigationVelocity));
                    break;
                case ActionNavigateBeeline.EASE_QUAD_IN:
                    this.m_progress = ActionNavigateBeeline.easeInQuad(this.m_elapsed, this.m_duration, 0, _local3);
                    break;
                case ActionNavigateBeeline.EASE_QUAD_OUT:
                    this.m_progress = ActionNavigateBeeline.easeOutQuad(this.m_elapsed, this.m_duration, 0, _local3);
                    break;
            };
            var _local4:int = int(((this.m_targetElevation - this.m_sourceElevation) / Math.abs((this.m_targetElevation - this.m_sourceElevation))));
            var _local5:Number = (Math.abs((this.m_progress - _local2)) * _local4);
            var _local6:Vector3 = m_npc.getPosition();
            m_npc.setPosition(_local6.x, _local6.y, (_local6.z + _local5));
            if (((!((this.m_direction == m_npc.getDirection()))) && (!((this.m_direction == -1))))){
                if ((m_npc is Vehicle)){
                    (m_npc as Vehicle).startTurnAnimation(this.m_direction);
                } else {
                    m_npc.setDirection(this.m_direction);
                    m_npc.setState(m_npc.getState());
                };
            };
            if ((((((this.m_progress >= _local3)) || ((this.m_elapsed >= this.m_duration)))) || ((m_npc.getPosition().z < 0)))){
                m_npc.setPosition(_local6.x, _local6.y, this.m_targetElevation);
                m_npc.getStateMachine().removeState(this);
            };
            m_npc.conditionallyReattach();
        }
        protected function updatePath():void{
            if (this.m_sourceElevation == -1){
                this.m_sourceElevation = m_npc.getPosition().z;
            };
            var _local1:Number = Math.abs((this.m_sourceElevation - this.m_targetElevation));
            this.m_duration = (_local1 / this.navigationVelocity);
            this.m_elapsed = 0;
            this.m_progress = 0;
            m_npc.setPosition(m_npc.getPosition().x, m_npc.getPosition().y, this.m_sourceElevation);
        }
        override public function enter():void{
            super.enter();
            this.updatePath();
        }
        override public function reenter():void{
            super.reenter();
            this.updatePath();
        }

    }
}//package Classes.actions 
